let AgentParse = (agent)=>{
    const ALL_BROWSER = {
        QQ_BROWSER:"qqbrowser",
        EDGE:"edge",
        IE:"msie",
        NEW_IE:"windows nt",
        FIRE_FOX:"firefox",
        OPERA:"opera",
        CHROME:"chrome",
        SAFARI:"safari",
        MAXTHON:"maxthon",
        UC:""
    };
    let browser = null;
    let preProcess = (agent)=>{
        agent = agent.toLowerCase();
        for(let key in ALL_BROWSER){
            if(agent.indexOf(ALL_BROWSER[key]) !== -1){
                browser = ALL_BROWSER[key];
            }
        }
    }
    preProcess(agent);

    let AgentParseExecutors = ()=>{
        let executors = {}
        let result = {
            os:"",
            browser:"",
            browserVersion:"",
            deviceName:""
        };
        let beforeExecute = ()=>{

        }
        beforeExecute();

        executors[ALL_BROWSER.QQ_BROWSER] = (agent)=>{

            return result;
        };
        executors[ALL_BROWSER.EDGE] = (agent)=>{

            return result;
        };
        executors[ALL_BROWSER.IE] = (agent)=>{

            return result;
        };
        executors[ALL_BROWSER.NEW_IE] = (agent)=>{

            return result;
        };

        executors[ALL_BROWSER.CHROME] = (agent)=>{

            return result;
        };
        executors[ALL_BROWSER.FIRE_FOX] = (agent)=>{

            return result;
        };
        executors[ALL_BROWSER.MAXTHON] = (agent)=>{

            return result;
        };
        executors[ALL_BROWSER.OPERA] = (agent)=>{

            return result;
        };
        executors[ALL_BROWSER.QQ_BROWSER] = (agent)=>{

            return result;
        };
        executors[ALL_BROWSER.UC] = (agent)=>{

            return result;
        };

        this.getAgentParseHandler = (name)=>{
            if(name == null){
                return (agent)=>{
                    console.log(agent)
                    return {};
                }
            }
            return executors[name];
        }
    }


    this.getDeviceInfo = ()=>{
        return new AgentParseExecutors().getAgentParseHandler(browser).call(agent);
    }

}

export function getDeviceInfo(agent){
    if(!agent){
        agent = navigator.userAgent;
    }
    return new AgentParse(agent).getDeviceInfo();
}